Function.RegisterNamespace("System.EnvironmentStrategy");
if(!System.EnvironmentStrategy.SpiderMonkey)throw new Error("System.EnvironmentStrategy.SpiderMonkey.Windows: Required dependency 'System.EnvironmentStrategy.SpiderMonkey' was not found. Are you missing a script reference?");

System.EnvironmentStrategy.SpiderMonkey.Windows=function(){
    var _outputFileName="SpiderMonkey_CommandOutput.tmp";

    this.base();

    // IEnvironmentStrategy members
    this.Execute=function(command,parameters,voidOutput){
        try{
            var fullCommand=[command].concat(parameters||[]).join(' ');
            var exitCode=system(voidOutput?fullCommand:[fullCommand,">",_outputFileName].join(' '));
            if(exitCode!=0)throw new Error(String.Format("Command '{0}' exited with code {1}.",fullCommand,exitCode));
            if(!voidOutput)return read(_outputFileName);
        }catch(e){
            throw e;
        }finally{
            system(String.Format("IF EXIST \"{0}\" del /F \"{0}\"",_outputFileName));
        }
    };

    this.GetNewLine=function(){
        return "\r\n";
    };

    this.GetWorkingDirectory=function(){
        return System.IO.Path.Normalize(String.Trim(this.Execute("cd")));
    };

    // IStrategySpecification members
    this.IsSatisfiedBy=function(candidate){
        if(this.base.IsSatisfiedBy(candidate)){
            try{
                var exitCode=system("ver > NUL 2>&1");
                if(exitCode==0){
                    System.IO.Path.DirectorySeparator="\\";
                    return true;
                }
            }catch(e){}
        }
        return false;
    };
};

System.EnvironmentStrategy.SpiderMonkey.Windows.Inherit(System.EnvironmentStrategy.SpiderMonkey,'System.EnvironmentStrategy.SpiderMonkey.Windows');

System.Environment.Strategies.Add(System.EnvironmentStrategy.SpiderMonkey.Windows);
